﻿using Basic.HrRemoteModel.Msg;
using Basic.HrRemoteModel.Msg.Model;
using WeDonekRpc.Client.Attr;

namespace Basic.FlowExtendService.lmpl
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class MsgService : IMsgService
    {
        public void MsgDone ( string LinkType, long linkPk, string tag )
        {
            new SetMsgDone
            {
                LinkPk = linkPk,
                LinkType = LinkType,
                Tag = tag
            }.Send();
        }
        public bool Send ( List<MsgAdd> adds, List<ToVoidItem> toVoids, List<MsgItem> done, out string error )
        {
            return new MsgBatchOpt
            {
                Adds = adds.ToArray(),
                Done = done.ToArray(),
                ToVoid = toVoids.ToArray()
            }.Send(out error);
        }

        public void Send ( MsgAdd add, ToVoidItem toVoid )
        {
            new MsgBatchOpt
            {
                Adds = new MsgAdd[] { add },
                ToVoid = toVoid == null ? null : new ToVoidItem[] { toVoid }
            }.Send();
        }

        public void SendMsg ( MsgAdd add )
        {
            new AddMsg
            {
                Datum = add
            }.Send();
        }
        public bool SendMsg ( MsgAdd add, out string error )
        {
            return new AddMsg
            {
                Datum = add
            }.Send(out error);
        }
        public void ToVoidMsg ( string LinkType, long linkPk, string tag )
        {
            new ToVoidMsg
            {
                LinkPk = linkPk,
                LinkType = LinkType,
                Tag = tag
            }.Send();
        }
        public void ToVoidMsg ( ToVoidItem[] msgs )
        {
            new BatchToVoidMsg
            {
                Items = msgs
            }.Send();
        }
    }
}
